﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SQLite;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace program1
{
    public partial class LogForm : Form
    {
        private System.Windows.Forms.Timer timer; // 定时器

        public LogForm()
        {
            InitializeComponent();
            BindLogData();

            // 初始化定时器
            timer = new System.Windows.Forms.Timer();
            timer.Interval = 4000; // 10秒刷新一次（根据需要调整刷新间隔）
            timer.Tick += Timer_Tick;
            timer.Start();
        }

        private void Timer_Tick(object sender, EventArgs e)
        {
            // 定时器触发时重新加载日志数据
            BindLogData();
        }

        private void BindLogData()
        {
            // 连接到数据库并查询日志数据
            string connectionString = "Data Source=SchoolManagement.db";
            using (SQLiteConnection connection = new SQLiteConnection(connectionString))
            {
                connection.Open();
                using (SQLiteCommand command = new SQLiteCommand("SELECT * FROM Logs", connection))
                using (SQLiteDataAdapter adapter = new SQLiteDataAdapter(command))
                {
                    DataTable logTable = new DataTable();
                    adapter.Fill(logTable);

                    // 绑定数据到 ListBox 控件
                    listBoxLog.DataSource = logTable;
                    listBoxLog.DisplayMember = "Details"; // 显示在 ListBox 中的列名
                }
            }
        }
    }
}
